﻿using BarTender;
using CKS.Core.Framework;
using S7.Net.Types;
//using Seagull.BarTender.Print;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace PrintMark.Helper
{
    public class PrinterHelper
    {


 　　　　public static void PrinterLabel(string printModePath, string printerName, Dictionary<string, string> paras, bool isPreview = false)
         {
             BarTender.Application BtApp = new BarTender.Application();
                       
             BarTender.Format btFormat =
                BtApp.Formats.Open(printModePath);
             btFormat.PrintSetup.Printer = printerName;

            if (paras != null)
            {
                foreach (var item in paras)
                {
                    //Print Label ,打印标签
                    btFormat.SetNamedSubStringValue(item.Key, item.Value);
                    //Reading Named Substrings ,读取标签字段
                   
                    
                }
            }
            BarTender.Messages messages = null;
            var result1 = btFormat.Print("PrintJob1",true,-1,out messages);
            btFormat.Close(BtSaveOptions.btDoNotSaveChanges);

            if (result1 == BtPrintResult.btFailure)
            {
                throw new Exception("打印失败");
            }
            if (result1 == BtPrintResult.btTimeout)
            {
                throw new Exception("打印超时，请检查");
            }
           
        }




       
    
    }
}
